package com.itheima.demo;/**
 *
 */

import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.pool.DruidPooledConnection;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.sql.Connection;
import java.sql.SQLException;

/**
 * @ClassName DemoDataSource
 * @Description TODO
 *  @Author $无小白$
 *  @Date 2020/8/25 0:07
 *  @Version 1.0
 **/
public class DemoDataSource {


    public void  testDruid() throws SQLException {
        /*创建数据库连接池对象*/
        DruidDataSource sd = new DruidDataSource();
        /*数据连接四大基本特征
        **/
        sd.setDriverClassName("com.mysql.jdbc.Driver");
        sd.setUrl("jdbc:mysql://localhost:3306/db666");
        sd.setUsername("root");
        sd.setPassword("root");
      Connection connection = sd.getConnection();


    }

    @Test
    public  void  test03() throws SQLException {
        //1创建ioc容器
       ApplicationContext ac = new ClassPathXmlApplicationContext("spring.xml");
       //从容器中获取数据源对象

        DruidDataSource bean = ac.getBean(DruidDataSource.class);
        DruidPooledConnection connection = bean.getConnection();
        System.out.println("connection = " + connection);

    }
}
